from django.contrib.auth.models import Group, User
import hashlib
from mr_edu.settings import ABSOLUTE_PATH
from core.models import Course
from core.semantic_manager import Semantic_manager

uri_root = 'http://thesis.eliacontini.info/semantic/'
md5 = hashlib.md5()
semantic_web = Semantic_manager(ABSOLUTE_PATH + 'rdfstore.db')

teachersGroup = Group(name = 'Teachers')
teachersGroup.save()
teachersGroupRDF = {
        'name': 'Teachers',
        'uri': uri_root + 'group/teachers/' + str(teachersGroup.id),
    }

studentsGroup = Group(name = 'Students')
studentsGroup.save()
studentsGroupRDF = {
        'name': 'Students',
        'uri': uri_root + 'group/students/' + str(studentsGroup.id),
    }

semantic_web.insertGroup(teachersGroupRDF)
semantic_web.insertGroup(studentsGroupRDF)

# teachers
elia = User.objects.create_user('elia', 'test@test.ch', 'test')
elia.first_name = 'Elia'
elia.last_name = 'Contini'
elia.groups.add(teachersGroup)
elia.save()
eliaRDF = {
        'name': 'Elia',
        'surname': 'Contini',
        'uri': uri_root + 'users/' + str(elia.id),
    }
semantic_web.insertUser(eliaRDF)

elisa = User.objects.create_user('elisa', 'test@test.ch', 'test')
elisa.first_name = 'Elisa'
elisa.last_name = 'Rubegni'
elisa.groups.add(teachersGroup)
elisa.save()
elisaRDF = {
        'name': 'Elisa',
        'surname': 'Rubegni',
        'uri': uri_root + 'users/' + str(elisa.id),
    }
semantic_web.insertUser(elisaRDF)

davide = User.objects.create_user('davide', 'test@test.ch', 'test')
davide.first_name = 'Davide'
davide.last_name = 'Eynard'
davide.groups.add(teachersGroup)
davide.save()
davideRDF = {
        'name': 'Davide',
        'surname': 'Eynard',
        'uri': uri_root + 'users/' + str(davide.id),
    }
semantic_web.insertUser(davideRDF)

# students
tizio = User.objects.create_user('tizio', 'test@test.ch', 'test')
tizio.first_name = 'Tizio'
tizio.last_name = 'Bianchi'
tizio.groups.add(studentsGroup)
tizio.save()
tizioRDF = {
        'name': 'Tizio',
        'surname': 'Bianchi',
        'uri': uri_root + 'users/' + str(tizio.id),
    }
semantic_web.insertUser(tizioRDF)

caio = User.objects.create_user('caio', 'test@test.ch', 'test')
caio.first_name = 'Caio'
caio.last_name = 'Celesti'
caio.groups.add(studentsGroup)
caio.save()
caioRDF = {
        'name': 'Caio',
        'surname': 'Celesti',
        'uri': uri_root + 'users/' + str(caio.id),
    }
semantic_web.insertUser(caioRDF)

sempronio = User.objects.create_user('sempronio', 'test@test.ch', 'test')
sempronio.first_name = 'Sempronio'
sempronio.last_name = 'Fucsi'
sempronio.groups.add(studentsGroup)
sempronio.save()
sempronioRDF = {
        'name': 'Sempronio',
        'surname': 'Fucsi',
        'uri': uri_root + 'users/' + str(sempronio.id),
    }
semantic_web.insertUser(sempronioRDF)

'''
mario = User.objects.create_user('mario', 'test@test.ch', 'test')
mario.first_name = 'Mario'
mario.last_name = 'Gialli'
mario.groups.add(studentsGroup)
mario.save()

anna = User.objects.create_user('anna', 'test@test.ch', 'test')
anna.first_name = 'Anna'
anna.last_name = 'Marroni'
anna.groups.add(studentsGroup)
anna.save()

pippo = User.objects.create_user('pippo', 'test@test.ch', 'test')
pippo.first_name = 'Pippo'
pippo.last_name = 'Arancioni'
pippo.groups.add(studentsGroup)
pippo.save()

pluto = User.objects.create_user('pluto', 'test@test.ch', 'test')
pluto.first_name = 'Pluto'
pluto.last_name = 'Verdi'
pluto.groups.add(studentsGroup)
pluto.save()

paperina = User.objects.create_user('paperina', 'test@test.ch', 'test')
paperina.first_name = 'Paperina'
paperina.last_name = 'Grigi'
paperina.groups.add(studentsGroup)
paperina.save()
'''

# courses
V_elementary = Course.objects.create(name = '5 Elementare', year = 2012, teacher = elia)
V_elementary.save()
V_elementary.students.add(tizio)
V_elementary.students.add(caio)
V_elementary.students.add(sempronio)
V_elementaryRDF = {
        'name': '5 Elementary 2012',
        'uri': uri_root + 'courses/' + str(V_elementary.id),
    }

# groups members
semantic_web.addGroupMember(teachersGroupRDF, eliaRDF)
semantic_web.addGroupMember(teachersGroupRDF, elisaRDF)
semantic_web.addGroupMember(teachersGroupRDF, davideRDF)

semantic_web.addGroupMember(studentsGroupRDF, tizioRDF)
semantic_web.addGroupMember(studentsGroupRDF, caioRDF)
semantic_web.addGroupMember(studentsGroupRDF, sempronioRDF)

semantic_web.addGroupMember(V_elementaryRDF, eliaRDF)
semantic_web.addGroupMember(V_elementaryRDF, tizioRDF)
semantic_web.addGroupMember(V_elementaryRDF, caioRDF)
semantic_web.addGroupMember(V_elementaryRDF, sempronioRDF)

# RDF debug
semantic_web.debug()
